package org.rsbot.script.methods;

import java.awt.Point;
import org.rsbot.client.Client;
import org.rsbot.script.internal.InputManager;

public class Mouse extends MethodProvider
{
  private int mouseSpeed = 10;

  Mouse(MethodContext paramMethodContext) {
    super(paramMethodContext);
  }

  public void moveRandomly(int paramInt)
  {
    moveRandomly(1, paramInt);
  }

  public void moveRandomly(int paramInt1, int paramInt2)
  {
    double d1 = Math.random();
    if (random(0, 2) == 1)
      d1 = -d1;
    double d2 = Math.sqrt(1.0D - d1 * d1);
    if (random(0, 2) == 1) {
      d2 = -d2;
    }
    double d3 = paramInt2;

    Point localPoint = getLocation();

    int i = (int)Math.round(d1 * d3 + localPoint.x);

    d3 -= Math.abs((i - Math.max(0, Math.min(this.methods.game.getWidth(), i))) / d1);

    int j = (int)Math.round(d2 * d3 + localPoint.y);
    d3 -= Math.abs((j - Math.max(0, Math.min(this.methods.game.getHeight(), j))) / d2);

    if (d3 < paramInt1) {
      return;
    }

    d3 = random(paramInt1, (int)d3);

    move((int)(d1 * d3) + localPoint.x, (int)(d2 * d3) + localPoint.y);
  }

  public void moveOffScreen()
  {
    if (isPresent())
      switch (random(0, 4)) {
      case 0:
        move(random(-10, this.methods.game.getWidth() + 10), random(-100, -10));

        break;
      case 1:
        move(random(-10, this.methods.game.getWidth() + 10), this.methods.game.getHeight() + random(10, 100));

        break;
      case 2:
        move(random(-100, -10), random(-10, this.methods.game.getHeight() + 10));

        break;
      case 3:
        move(random(10, 100) + this.methods.game.getWidth(), random(-10, this.methods.game.getHeight() + 10));
      }
  }

  public void drag(int paramInt1, int paramInt2)
  {
    this.methods.inputManager.dragMouse(paramInt1, paramInt2);
  }

  public void drag(Point paramPoint)
  {
    drag(paramPoint.x, paramPoint.y);
  }

  public void click(boolean paramBoolean)
  {
    click(paramBoolean, 0);
  }

  public synchronized void click(boolean paramBoolean, int paramInt) {
    this.methods.inputManager.clickMouse(paramBoolean);
    if (paramInt > 0) {
      sleep(random(50, 350));
      Point localPoint = getLocation();
      move(localPoint.x - paramInt, localPoint.y - paramInt, paramInt * 2, paramInt * 2);
    }
  }

  public void click(int paramInt1, int paramInt2, boolean paramBoolean)
  {
    click(paramInt1, paramInt2, 0, 0, paramBoolean);
  }

  public synchronized void click(int paramInt1, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean)
  {
    move(paramInt1, paramInt2, paramInt3, paramInt4);
    sleep(random(50, 350));
    click(paramBoolean, 0);
  }

  public synchronized void click(int paramInt1, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean, int paramInt5)
  {
    move(paramInt1, paramInt2, paramInt3, paramInt4);
    sleep(random(50, 350));
    click(paramBoolean, paramInt5);
  }

  public void click(Point paramPoint, boolean paramBoolean)
  {
    click(paramPoint.x, paramPoint.y, paramBoolean);
  }

  public void click(Point paramPoint, int paramInt1, int paramInt2, boolean paramBoolean) {
    click(paramPoint.x, paramPoint.y, paramInt1, paramInt2, paramBoolean);
  }

  public void click(Point paramPoint, int paramInt1, int paramInt2, boolean paramBoolean, int paramInt3)
  {
    click(paramPoint.x, paramPoint.y, paramInt1, paramInt2, paramBoolean, paramInt3);
  }

  public void clickSlightly()
  {
    Point localPoint = new Point((int)(getLocation().getX() + (Math.random() * 50.0D > 25.0D ? 1 : -1) * (30.0D + Math.random() * 90.0D)), (int)(getLocation().getY() + (Math.random() * 50.0D > 25.0D ? 1 : -1) * (30.0D + Math.random() * 90.0D)));

    if ((localPoint.getX() < 1.0D) || (localPoint.getY() < 1.0D) || (localPoint.getX() > 761.0D) || (localPoint.getY() > 499.0D)) {
      clickSlightly();
      return;
    }
    click(localPoint, true);
  }

  public int getSpeed()
  {
    return this.mouseSpeed;
  }

  public void setSpeed(int paramInt)
  {
    this.mouseSpeed = paramInt;
  }

  public void move(int paramInt1, int paramInt2)
  {
    move(paramInt1, paramInt2, 0, 0);
  }

  public void move(int paramInt1, int paramInt2, int paramInt3)
  {
    move(getSpeed(), paramInt1, paramInt2, 0, 0, paramInt3);
  }

  public void move(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    move(getSpeed(), paramInt1, paramInt2, paramInt3, paramInt4, 0);
  }

  public void move(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5)
  {
    move(paramInt1, paramInt2, paramInt3, paramInt4, paramInt5, 0);
  }

  public synchronized void move(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6)
  {
    if ((paramInt2 != -1) || (paramInt3 != -1)) {
      this.methods.inputManager.moveMouse(paramInt1, paramInt2, paramInt3, paramInt4, paramInt5);
      if (paramInt6 > 0) {
        sleep(random(60, 300));
        Point localPoint = getLocation();
        move(localPoint.x - paramInt6, localPoint.y - paramInt6, paramInt6 * 2, paramInt6 * 2);
      }
    }
  }

  public void move(int paramInt, Point paramPoint)
  {
    move(paramInt, paramPoint.x, paramPoint.y, 0, 0, 0);
  }

  public void move(Point paramPoint)
  {
    move(paramPoint.x, paramPoint.y, 0, 0);
  }

  public void move(Point paramPoint, int paramInt)
  {
    move(getSpeed(), paramPoint.x, paramPoint.y, 0, 0, paramInt);
  }

  public void move(Point paramPoint, int paramInt1, int paramInt2)
  {
    move(paramPoint.x, paramPoint.y, paramInt1, paramInt2);
  }

  public void move(Point paramPoint, int paramInt1, int paramInt2, int paramInt3)
  {
    move(getSpeed(), paramPoint.x, paramPoint.y, paramInt1, paramInt2, paramInt3);
  }

  public synchronized void hop(int paramInt1, int paramInt2)
  {
    this.methods.inputManager.hopMouse(paramInt1, paramInt2);
  }

  public void hop(Point paramPoint)
  {
    hop(paramPoint.x, paramPoint.y);
  }

  public void hop(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    hop(paramInt1 + random(-paramInt3, paramInt3), paramInt2 + random(-paramInt3, paramInt4));
  }

  public void hop(Point paramPoint, int paramInt1, int paramInt2)
  {
    hop(paramPoint.x, paramPoint.y, paramInt1, paramInt2);
  }

  public void moveSlightly()
  {
    Point localPoint = new Point((int)(getLocation().getX() + (Math.random() * 50.0D > 25.0D ? 1 : -1) * (30.0D + Math.random() * 90.0D)), (int)(getLocation().getY() + (Math.random() * 50.0D > 25.0D ? 1 : -1) * (30.0D + Math.random() * 90.0D)));

    if ((localPoint.getX() < 1.0D) || (localPoint.getY() < 1.0D) || (localPoint.getX() > 761.0D) || (localPoint.getY() > 499.0D)) {
      moveSlightly();
      return;
    }
    move(localPoint);
  }

  public int getRandomX(int paramInt)
  {
    Point localPoint = getLocation();
    if ((localPoint.x < 0) || (paramInt <= 0))
      return -1;
    if (random(0, 2) == 0) {
      return localPoint.x - random(0, localPoint.x < paramInt ? localPoint.x : paramInt);
    }
    int i = this.methods.game.getWidth() - localPoint.x;
    return localPoint.x + random(1, (i < paramInt) && (i > 0) ? i : paramInt);
  }

  public int getRandomY(int paramInt)
  {
    Point localPoint = getLocation();
    if ((localPoint.y < 0) || (paramInt <= 0))
      return -1;
    if (random(0, 2) == 0) {
      return localPoint.y - random(0, localPoint.y < paramInt ? localPoint.y : paramInt);
    }
    int i = this.methods.game.getHeight() - localPoint.y;
    return localPoint.y + random(1, (i < paramInt) && (i > 0) ? i : paramInt);
  }

  public Point getLocation()
  {
    org.rsbot.client.input.Mouse localMouse = this.methods.client.getMouse();
    return new Point(localMouse.getX(), localMouse.getY());
  }

  public Point getPressLocation()
  {
    org.rsbot.client.input.Mouse localMouse = this.methods.client.getMouse();
    return new Point(localMouse.getPressX(), localMouse.getPressY());
  }

  public long getPressTime()
  {
    org.rsbot.client.input.Mouse localMouse = this.methods.client.getMouse();
    return localMouse == null ? 0L : localMouse.getPressTime();
  }

  public boolean isPresent()
  {
    org.rsbot.client.input.Mouse localMouse = this.methods.client.getMouse();
    return (localMouse != null) && (localMouse.isPresent());
  }

  public boolean isPressed()
  {
    org.rsbot.client.input.Mouse localMouse = this.methods.client.getMouse();
    return (localMouse != null) && (localMouse.isPressed());
  }
}